package com.bauer.framework.autumn.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author ：rui.wei
 * @Date ：Created in 16:11 2018/7/20
 * @Description：
 */
public class PathUtils {


    public static List<String> getFiles(File file,List<String> classesPaths){

        if ( file.isFile()) {
            classesPaths.add(file.getPath());
        }else {
            File[] files = file.listFiles();
            for (File file1 : files){
                    getFiles(file1,classesPaths);
            }
        }
        return classesPaths;
    }

    public static List<String> getPkgPath(String classpath,String pkgPath){
        File classpathFile =  new File(classpath);
        List<String> filesPaths = getFiles(new File(classpath+pkgPath.replace(".","\\")),new ArrayList<String>());
        List<String> pkgPaths = new ArrayList<>();
        for (String path :filesPaths){
            String pkg = path.replace(classpathFile.getPath(),"").replace("\\",".");
            pkgPaths.add(pkg.substring(1,pkg.lastIndexOf(".")));
        }
        return pkgPaths;
    }
}
